package day13;

import org.junit.Before;
import org.junit.Test;

import java.util.Iterator;
import java.util.List;

import java.util.ArrayList;

//添加泛型后 集合遍历
public class TestLoop2 {
    List<String> list=new ArrayList();

    @Before
    public void beffore(){
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        list.add("ddd");
    }
    @Test
    public void test1(){
        for (int i=0;i< list.size();i++){
            String s=list.get(i);
            System.out.println(s);
        }
    }

    @Test
    public void test2(){
        for (String s:list){
            System.out.println(s);
        }
    }

    @Test
    public void test3(){
        Iterator<String> it=list.iterator();
        while (it.hasNext()){
            String s=it.next();
            System.out.println(s);
        }
    }
}
